extern crate ffilib;
use ffilib::preg_match;

use std::str;
use std::error::Error;
use std::net::SocketAddr;
use tokio::net::UdpSocket;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let pattern = r"\d{4}([a-zA-Z_()]{3,11})\S+";
    let subject = "a;jhgoqoghqoj0329 u0tyu10hg0h9Y0Y9827342482y(Y0y(G)_)lajf;lqjfgqhgpqjopjqa=)*(^!@#$%^&*())9999999";
    let ret = preg_match(pattern.to_string(), subject.to_string())?;

    let addr = "0.0.0.0:9191";
    let addr = addr.parse::<SocketAddr>()?;
    let bind_addr = "0.0.0.0:0";
    let socket = UdpSocket::bind(&bind_addr).await?;
    socket.connect(addr).await?;
    socket.send(ret[1].as_bytes()).await?;
    let mut buf = vec![0; 1024];
    let n = socket.recv(&mut buf[..]).await?;
    println!("{}",str::from_utf8(&buf[..n]).unwrap());
    Ok(())
}